package ws.performancetest.app.gui.dialog;

import javax.swing.JDialog;
import javax.swing.JOptionPane;
import ws.performancetest.app.gui.strings.AppStrings;

/**
 * Dialog for asking "yes no" questions to the user.
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class YesNoDialog extends JOptionPane {

  /* Object reference to this class. */
  private static final YesNoDialog reference = new YesNoDialog();

  private YesNoDialog() {
    /* Set user options: yes or no. */
    options = new String[] {AppStrings.yes, AppStrings.no};
  }

  /**
   * Ask the user some question.
   *
   * @param message question to be asked.
   *
   * @return {@code true} if the user answered yes, {@code false} otherwise.
   */
  public static boolean confirm(String message) {
    reference.setMessage(message);
    JDialog dialog = reference.createDialog("Confirm");
    dialog.setVisible(true);
    Object answer = reference.getValue();
    return answer.equals(AppStrings.yes)? true : false;
  }
}
